<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>固定定位</title>
  <style>
    body {
      margin: 0;
    }

    .outer {
      margin: 50px;
      width: 500px;
      height: 3500px;
      background-color: lightgreen;
    }

    .inner {
      /* 设置固定定位 */
      position: fixed;
      top: 0;
      width: 200px;
      height: 200px;
      background-color: lightpink;
    }
  </style>
</head>

<body>
  <div class="outer">
    <div class="inner"></div>
  </div>
</body>

</html>